<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;

class TrimStrings extends Middleware
{
    /**
     * 去掉邮编和电话号码中的'-'
     * 郵便番号と電話番号の「-」を削除します
     * @param \Illuminate\Http\Request $request
     * @param Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $request['input'] = $request->input();
        foreach ($request->input() as $key => $value) {
            if (in_array($key, ['working_school_zip', 'working_school_tel'])) {
                $request[$key] = str_replace('-', '', $value);
            }
        }
        return parent::handle($request, $next);
    }
}
